home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / ole2book.zip / CHAP10.ZIP / CHAP10 / SCHMOO / SCHMOO.CPP < prev    next >
C/C++ Source or Header  |  1993-06-23  |  21KB  |  886 lines

  1. /*
  2.  * SCHMOO.CPP
  3.  * Chapter 10 Modifications
  4.  * WinMain and CSchmooFrame implementations.
  5.  *
  6.  * Copyright (c)1993 Microsoft Corporation, All Rights Reserved
  7.  *
  8.  * Kraig Brockschmidt, Software Design Engineer
  9.  * Microsoft Systems Developer Relations
  10.  *
  11.  * Internet  :  kraigb@microsoft.com
  12.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  13.  */
  14.  
  15.  
  16. #define INITGUIDS
  17. #include "schmoo.h"
  18.  
  19. //CHAPTER10MOD
  20. //Count number of objects and number of locks.
  21. ULONG       g_cObj=0;
  22. ULONG       g_cLock=0;
  23.  
  24. //Make window handle global so other code can cause a shutdown
  25. HWND        g_hWnd=NULL;
  26.  
  27. //Indicate if the user has control
  28. BOOL        g_fUser=TRUE;
  29. //End CHAPTER10MOD
  30.  
  31.  
  32.  
  33. /*
  34.  * WinMain
  35.  *
  36.  * Purpose:
  37.  *  Main entry point of application.   Should register the app class
  38.  *  if a previous instance has not done so and do any other one-time
  39.  *  initializations.
  40.  */
  41.  
  42. int PASCAL WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR pszCmdLine, int nCmdShow)
  43.     {
  44.     LPCSchmooFrame  pFR;
  45.     FRAMEINIT       fi;
  46.     WPARAM          wRet;
  47.  
  48.    #ifndef WIN32
  49.     SetMessageQueue(96);
  50.    #endif
  51.  
  52.     //Attempt to allocate and initialize the application
  53.     pFR=new CSchmooFrame(hInst, hPrev, pszCmdLine, nCmdShow);
  54.  
  55.     fi.idsMin=IDS_FRAMEMIN;
  56.     fi.idsMax=IDS_FRAMEMAX;
  57.     fi.idsStatMin=IDS_STATMESSAGEMIN;
  58.     fi.idsStatMax=IDS_STATMESSAGEMAX;
  59.     fi.idStatMenuMin=ID_MENUFILE;
  60.     fi.idStatMenuMax=ID_MENUHELP;
  61.     fi.iPosWindowMenu=WINDOW_MENU;
  62.     fi.cMenus=CMENUS;
  63.  
  64.     //If we can initialize pFR, start chugging messages
  65.     if (pFR->FInit(&fi))
  66.         wRet=pFR->MessageLoop();
  67.  
  68.     delete pFR;
  69.     return wRet;
  70.     }
  71.  
  72.  
  73.  
  74. //CHAPTER10MOD
  75. /*
  76.  * ObjectDestroyed
  77.  *
  78.  * Purpose:
  79.  *  Function for the Schmoo Figure object to call when it gets destroyed.
  80.  *  We destroy the main window if the proper conditions are met for
  81.  *  shutdown.
  82.  *
  83.  * Parameters:
  84.  *  None
  85.  *
  86.  * Return Value:
  87.  *  None
  88.  */
  89.  
  90. void FAR PASCAL ObjectDestroyed(void)
  91.     {
  92.     g_cObj--;
  93.  
  94.     //No more objects, no locks, no user control, shut the app down.
  95.     if (0==g_cObj && 0==g_cLock && IsWindow(g_hWnd) && !g_fUser)
  96.         PostMessage(g_hWnd, WM_CLOSE, 0, 0L);
  97.  
  98.     return;
  99.     }
  100. //CHAPTER10MOD
  101.  
  102.  
  103.  
  104.  
  105. /*
  106.  * CSchmooFrame::CSchmooFrame
  107.  * CSchmooFrame::~CSchmooFrame
  108.  *
  109.  * Constructor Parameters:
  110.  *  hInst           HINSTANCE from WinMain
  111.  *  hInstPrev       HINSTANCE from WinMain
  112.  *  pszCmdLine      LPSTR from WinMain
  113.  *  nCmdShow        int from WInMain
  114.  */
  115.  
  116. CSchmooFrame::CSchmooFrame(HINSTANCE hInst, HINSTANCE hInstPrev
  117.     , LPSTR pszCmdLine, int nCmdShow)
  118.     : CFrame(hInst, hInstPrev, pszCmdLine, nCmdShow)
  119.     {
  120.     UINT        i;
  121.     //CHAPTER10MOD
  122.     char        szTemp[256];
  123.     //End CHAPTER10MOD
  124.  
  125.     for (i=0; i<5; i++)
  126.         m_hBmpLines[i]=NULL;
  127.  
  128.     m_fInitialized=FALSE;
  129.  
  130.     //CHAPTER10MOD
  131.     m_fEmbedding=FALSE;
  132.     //This function is in OLE2UI
  133.     ParseCmdLine(m_pszCmdLine, &m_fEmbedding, szTemp);
  134.     g_fUser=m_fEmbedding;
  135.     m_dwRegCO=0;
  136.     m_pIClassFactory=NULL;
  137.     //End CHAPTER10MOD
  138.  
  139.     return;
  140.     }
  141.  
  142.  
  143. CSchmooFrame::~CSchmooFrame(void)
  144.     {
  145.     UINT            i;
  146.  
  147.     //CHAPTER10MOD
  148.     //Opposite of CoRegisterClassObject, takes class factory ref to 1
  149.     if (0L!=m_dwRegCO)
  150.         CoRevokeClassObject(m_dwRegCO);
  151.  
  152.     //This should be the last ::Release, which frees the class factory.
  153.     if (NULL!=m_pIClassFactory)
  154.         m_pIClassFactory->Release();
  155.     //End CHAPTER10MOD
  156.  
  157.     for (i=0; i<5; i++)
  158.         DeleteObject(m_hBmpLines[i]);
  159.  
  160.     OleFlushClipboard();
  161.  
  162.     if (m_fInitialized)
  163.         OleUninitialize();
  164.  
  165.     return;
  166.     }
  167.  
  168.  
  169.  
  170.  
  171. /*
  172.  * CSchmooFrame::FInit
  173.  *
  174.  * Purpose:
  175.  *  Call CoInitialize then calling down into the base class
  176.  *  initialization.
  177.  *
  178.  * Parameters:
  179.  *  pFI             LPFRAMEINIT containing initialization parameters.
  180.  *
  181.  * Return Value:
  182.  *  BOOL            TRUE if initialization succeeded, FALSE otherwise.
  183.  */
  184.  
  185. BOOL CSchmooFrame::FInit(LPFRAMEINIT pFI)
  186.     {
  187.     DWORD       dwVer;
  188.     //CHAPTER10MOD
  189.     HRESULT     hr;
  190.     //End CHAPTER10MOD
  191.  
  192.     //We need OLE versions of Initialize for Clipboard
  193.     dwVer=OleBuildVersion();
  194.  
  195.     if (rmm!=HIWORD(dwVer))
  196.         return FALSE;
  197.  
  198.     if (FAILED(OleInitialize(NULL)))
  199.         return FALSE;
  200.  
  201.     m_fInitialized=TRUE;
  202.  
  203.     //CHAPTER10MOD
  204.     /*
  205.      * Create our class factory and register it for this application
  206.      * using CoRegisterClassObject.  The REGCLS_*USE flags have to do
  207.      * with servicable object from this instance, not with MDI or SDI.
  208.      * Since it's most convenient to be single use, we'll do this in
  209.      * either version.
  210.      *
  211.      * In addition, it only makes sense to do any of this if we're being
  212.      * launched to be a server.
  213.      */
  214.     if (m_fEmbedding)
  215.         {
  216.         m_pIClassFactory=new CFigureClassFactory(this);
  217.  
  218.         if (NULL==m_pIClassFactory)
  219.             return FALSE;
  220.  
  221.         //Since we hold on to this, we should AddRef it.
  222.         m_pIClassFactory->AddRef();
  223.  
  224.         hr=CoRegisterClassObject(CLSID_Schmoo2Figure, (LPUNKNOWN)m_pIClassFactory
  225.             , CLSCTX_LOCAL_SERVER, REGCLS_SINGLEUSE, &m_dwRegCO);
  226.  
  227.         if (FAILED(hr))
  228.             return FALSE;
  229.         }
  230.     //End CHAPTER10MOD
  231.  
  232.     return CFrame::FInit(pFI);
  233.     }
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240. /*
  241.  * CSchmooFrame::CreateCClient
  242.  *
  243.  * Purpose:
  244.  *  Constructs a new client specific to the application.
  245.  *
  246.  * Parameters:
  247.  *  None
  248.  *
  249.  * Return Value:
  250.  *  LPCClient       Pointer to the new client object.
  251.  */
  252.  
  253. LPCClient CSchmooFrame::CreateCClient(void)
  254.     {
  255.     return (LPCClient)(new CSchmooClient(m_hInst));
  256.     }
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265. /*
  266.  * CSchmooFrame::FRegisterAllClasses
  267.  *
  268.  * Purpose:
  269.  *  Registers all classes used in this application.
  270.  *
  271.  * Parameters:
  272.  *  None
  273.  *
  274.  * Return Value:
  275.  *  BOOL            TRUE if registration succeeded, FALSE otherwise.
  276.  */
  277.  
  278. BOOL CSchmooFrame::FRegisterAllClasses(void)
  279.     {
  280.     WNDCLASS        wc;
  281.  
  282.     //First let the standard frame do its thing
  283.     if (!CFrame::FRegisterAllClasses())
  284.         return FALSE;
  285.  
  286.     wc.style         = CS_HREDRAW | CS_VREDRAW;
  287.     wc.hInstance     = m_hInst;
  288.     wc.cbClsExtra    = 0;
  289.     wc.lpfnWndProc   = PolylineWndProc;
  290.     wc.cbWndExtra    = CBPOLYLINEWNDEXTRA;
  291.     wc.hIcon         = NULL;
  292.     wc.hCursor       = LoadCursor(NULL, IDC_CROSS);
  293.     wc.hbrBackground = NULL;
  294.     wc.lpszMenuName  = NULL;
  295.     wc.lpszClassName = SZCLASSPOLYLINE;
  296.  
  297.     if (!RegisterClass(&wc))
  298.         return FALSE;
  299.  
  300.     return TRUE;
  301.     }
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308. /*
  309.  * CSchmooFrame::FPreShowInit
  310.  *
  311.  * Purpose:
  312.  *  Called from FInit before intially showing the window.  We do whatever
  313.  *  else we want here, modifying m_nCmdShow as necessary which affects
  314.  *  ShowWindow in FInit.
  315.  *
  316.  * Parameters:
  317.  *  None
  318.  *
  319.  * Return Value:
  320.  *  BOOL            TRUE if this initialization succeeded, FALSE otherwise.
  321.  */
  322.  
  323. BOOL CSchmooFrame::FPreShowInit(void)
  324.     {
  325.     CreateLineMenu();
  326.     CheckLineSelection(IDM_LINESOLID);
  327.     m_pGB->Check(IDM_LINESOLID, TRUE);
  328.  
  329.     //CHAPTER10MOD
  330.     //Save the window handle for shutdown if necessary.
  331.     g_hWnd=m_hWnd;
  332.  
  333.     //If we're -Embedding, don't show the window initially.
  334.     if (m_fEmbedding)
  335.         m_nCmdShow=SW_HIDE;
  336.     //End CHAPTER10MOD
  337.  
  338.     return TRUE;
  339.     }
  340.  
  341.  
  342.  
  343. //CHAPTER10MOD
  344. /*
  345.  * CSchmooFrame::ParseCommandLine
  346.  *
  347.  * Purpose:
  348.  *  Allows the application to parse the command line and take action
  349.  *  after the window has possibly been shown.  For a compound document
  350.  *  server we need to just make sure that if -Embedding is there that
  351.  *  we take no file action.  FPreShowInit has already handled the
  352.  *  window visibility.
  353.  *
  354.  * Parameters:
  355.  *  None
  356.  *
  357.  * Return Value:
  358.  *  BOOL            TRUE if this initialization succeeded, FALSE otherwise.
  359.  */
  360.  
  361. void CSchmooFrame::ParseCommandLine(void)
  362.     {
  363.     //If -Embedding was there, prevent any  attempt at loading a file.
  364.     if (m_fEmbedding)
  365.         return;
  366.  
  367.     CFrame::ParseCommandLine();
  368.     return;
  369.     }
  370. //End CHAPTER10MOD
  371.  
  372.  
  373.  
  374.  
  375.  
  376. /*
  377.  * CSchmooFrame::CreateLineMenu
  378.  *
  379.  * Purpose:
  380.  *  Initializes the bitmaps used to create the Line menu and replaces
  381.  *  the text items defined in the application resources with these
  382.  *  bitmaps.  Note that the contents of m_hBmpLines must be cleaned
  383.  *  up when the application terminates.
  384.  *
  385.  * Parameters:
  386.  *  None
  387.  *
  388.  * Return Value:
  389.  *  None
  390.  */
  391.  
  392. void CSchmooFrame::CreateLineMenu(void)
  393.     {
  394.     HMENU       hMenu;
  395.     HDC         hDC, hMemDC;
  396.     HPEN        hPen;
  397.     HGDIOBJ     hObj;
  398.     TEXTMETRIC  tm;
  399.     UINT        i, cx, cy;
  400.  
  401.  
  402.     hMenu=GetSubMenu(GetMenu(m_hWnd), 3);   //Line menu.
  403.     hDC=GetDC(m_hWnd);
  404.  
  405.     //Create each line in a menu item 8 chars wide, one char high.
  406.     GetTextMetrics(hDC, &tm);
  407.     cx=tm.tmAveCharWidth*8;
  408.     cy=tm.tmHeight;
  409.  
  410.     //Create a memory DC in which to draw lines, and bitmaps for each line.
  411.     hMemDC=CreateCompatibleDC(hDC);
  412.     ReleaseDC(m_hWnd, hDC);
  413.  
  414.     for (i=0; i<5; i++)
  415.         {
  416.         m_hBmpLines[i]=CreateCompatibleBitmap(hMemDC, cx, cy);
  417.         SelectObject(hMemDC, m_hBmpLines[i]);
  418.  
  419.         PatBlt(hMemDC, 0, 0, cx, cy, WHITENESS);
  420.  
  421.         hPen=CreatePen(i, 1, 0L);           //i==line style like PS_SOLID
  422.         hObj=SelectObject(hMemDC, hPen);
  423.  
  424.         MoveTo(hMemDC, 0,  cy/2);
  425.         LineTo(hMemDC, cx, cy/2);
  426.  
  427.         ModifyMenu(hMenu, IDM_LINEMIN+i, MF_BYCOMMAND | MF_BITMAP
  428.             , IDM_LINEMIN+i, (LPCSTR)MAKELONG(m_hBmpLines[i], 0));
  429.  
  430.         SelectObject(hMemDC, hObj);
  431.         DeleteObject(hPen);
  432.         }
  433.  
  434.     CheckMenuItem(hMenu, IDM_LINESOLID, MF_CHECKED);
  435.     DeleteDC(hMemDC);
  436.  
  437.     return;
  438.     }
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448. /*
  449.  * CSchmooFrame::CreateGizmos
  450.  *
  451.  * Purpose:
  452.  *  Procedure to create all the necessary gizmobar buttons.
  453.  *
  454.  * Parameters:
  455.  *  None
  456.  *
  457.  * Return Value:
  458.  *  UINT            Number of gizmos added to the bar.
  459.  */
  460.  
  461. UINT CSchmooFrame::CreateGizmos(void)
  462.     {
  463.     UINT            iLast;
  464.     UINT            uState=GIZMO_NORMAL;
  465.     UINT            utCmd =GIZMOTYPE_BUTTONCOMMAND;
  466.     UINT            utEx  =GIZMOTYPE_BUTTONATTRIBUTEEX;
  467.  
  468.     //Insert the standard ones.
  469.     iLast=CFrame::CreateGizmos();
  470.  
  471.     //Insert File Import in the 5th position and account for it in iLast.
  472.     m_pGB->Add(utCmd, 4, IDM_FILEIMPORT, m_dxB, m_dyB, NULL, m_hBmp, 2, uState);
  473.     iLast++;
  474.  
  475.     //Separator
  476.     m_pGB->Add(GIZMOTYPE_SEPARATOR, iLast++, 0, 6, m_dyB, NULL, NULL, 0, uState);
  477.  
  478.     //For the Background bitmap, preserve our use of black (part of the image)
  479.     m_pGB->Add(utCmd, iLast++, IDM_COLORBACKGROUND, m_dxB, m_dyB, NULL, m_hBmp, 3
  480.                , GIZMO_NORMAL | PRESERVE_BLACK);
  481.  
  482.     m_pGB->Add(utCmd, iLast++, IDM_COLORLINE, m_dxB, m_dyB, NULL, m_hBmp, 4, uState);
  483.  
  484.     //Separator
  485.     m_pGB->Add(GIZMOTYPE_SEPARATOR, iLast++, 0, 6, m_dyB, NULL, NULL, 0, uState);
  486.  
  487.     //Line styles.
  488.     m_pGB->Add(utEx, iLast++, IDM_LINESOLID,      m_dxB, m_dyB, NULL, m_hBmp, 5, uState);
  489.     m_pGB->Add(utEx, iLast++, IDM_LINEDASH,       m_dxB, m_dyB, NULL, m_hBmp, 6, uState);
  490.     m_pGB->Add(utEx, iLast++, IDM_LINEDOT,        m_dxB, m_dyB, NULL, m_hBmp, 7, uState);
  491.     m_pGB->Add(utEx, iLast++, IDM_LINEDASHDOT,    m_dxB, m_dyB, NULL, m_hBmp, 8, uState);
  492.     m_pGB->Add(utEx, iLast++, IDM_LINEDASHDOTDOT, m_dxB, m_dyB, NULL, m_hBmp, 9, uState);
  493.  
  494.     return iLast;
  495.     }
  496.  
  497.  
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504. /*
  505.  * CSchmooFrame::OnCommand
  506.  *
  507.  * Purpose:
  508.  *  WM_COMMAND handler for the Schmoo frame window that just processes
  509.  *  the line menu and the color menu leaving the CFrame to do everything
  510.  *  else.
  511.  *
  512.  * Parameters:
  513.  *  hWnd            HWND of the frame window.
  514.  *  wParam          WPARAM of the message.
  515.  *  lParam          LPARAM of the message.
  516.  *
  517.  * Return Value:
  518.  *  LRESULT         Return value for the message.
  519.  */
  520.  
  521. LRESULT CSchmooFrame::OnCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
  522.     {
  523.     LPCSchmooDoc    pDoc;
  524.     char            szFile[CCHPATHMAX];
  525.     BOOL            fOK;
  526.     UINT            i, uTemp;
  527.     COLORREF        rgColors[16];
  528.     CHOOSECOLOR     cc;
  529.  
  530.     COMMANDPARAMS(wID, wCode, hWndMsg);
  531.  
  532.     /*
  533.      * Don't bother with anything during first initialization,
  534.      * skipping many GizmoBar notifications.
  535.      */
  536.     if (m_fInit)
  537.         return 0L;
  538.  
  539.     pDoc=(LPCSchmooDoc)m_pCL->ActiveDocument();
  540.  
  541.     /*
  542.      * Check for the line style commands which are IDM_LINEMIN+<style>.
  543.      * We handle this by changing the menu and toolbar, then we pass
  544.      * it to the document for real processing.
  545.      */
  546.     if (NULL!=pDoc && IDM_LINEMIN <= wID && IDM_LINEMAX >=wID)
  547.         {
  548.         CheckLineSelection(wID);
  549.         pDoc->LineStyleSet(wID-IDM_LINEMIN);
  550.         return 0L;
  551.         }
  552.  
  553.     switch (wID)
  554.         {
  555.         case IDM_FILEIMPORT:
  556.             szFile[0]=0;
  557.             fOK=FSaveOpenDialog(szFile, CCHPATHMAX, IDS_FILEIMPORT, TRUE, &i);
  558.  
  559.             if (fOK)
  560.                 {
  561.                 uTemp=pDoc->ULoad(FALSE, szFile);
  562.                 pDoc->ErrorMessage(uTemp);
  563.                 }
  564.  
  565.             return (LRESULT)fOK;
  566.  
  567.  
  568.         case IDM_COLORBACKGROUND:
  569.         case IDM_COLORLINE:
  570.             //Invoke the color chooser for either color
  571.             uTemp=(IDM_COLORBACKGROUND==wID)
  572.                 ? DOCCOLOR_BACKGROUND : DOCCOLOR_LINE;
  573.  
  574.             for (i=0; i<16; i++)
  575.                 rgColors[i]=RGB(0, 0, i*16);
  576.  
  577.             memset(&cc, 0, sizeof(CHOOSECOLOR));
  578.             cc.lStructSize=sizeof(CHOOSECOLOR);
  579.             cc.lpCustColors=rgColors;
  580.             cc.hwndOwner=hWnd;
  581.             cc.Flags=CC_RGBINIT;
  582.             cc.rgbResult=pDoc->ColorGet(uTemp);
  583.  
  584.             if (ChooseColor(&cc))
  585.                 pDoc->ColorSet(uTemp, cc.rgbResult);
  586.  
  587.             break;
  588.  
  589.  
  590.         default:
  591.            CFrame::OnCommand(hWnd, wParam, lParam);
  592.         }
  593.  
  594.     return 0L;
  595.     }
  596.  
  597.  
  598.  
  599.  
  600.  
  601.  
  602. /*
  603.  * CSchmooFrame::OnDocumentDataChange
  604.  *
  605.  * Purpose:
  606.  *  Update the Line menu and GizmoBar if the style in the data changes.
  607.  *
  608.  * Parameters:
  609.  *  pDoc            LPCDocument notifying the sink.
  610.  *
  611.  * Return Value:
  612.  *  None
  613.  */
  614.  
  615. void CSchmooFrame::OnDocumentDataChange(LPCDocument pDoc)
  616.     {
  617.     CheckLineSelection(IDM_LINEMIN+((LPCSchmooDoc)pDoc)->LineStyleGet());
  618.     return;
  619.     }
  620.  
  621.  
  622.  
  623.  
  624. /*
  625.  * CSchmooFrame::OnDocumentActivate
  626.  *
  627.  * Purpose:
  628.  *  Informs us that document activation changed, so update the UI for
  629.  *  that new document.
  630.  *
  631.  * Parameters:
  632.  *  pDoc            LPCDocument notifying the sink.
  633.  *
  634.  * Return Value:
  635.  *  None
  636.  */
  637.  
  638. void CSchmooFrame::OnDocumentActivate(LPCDocument pDoc)
  639.     {
  640.     CheckLineSelection(IDM_LINEMIN+((LPCSchmooDoc)pDoc)->LineStyleGet());
  641.     return;
  642.     }
  643.  
  644.  
  645.  
  646.  
  647.  
  648.  
  649.  
  650. /*
  651.  * CSchmooFrame::UpdateMenus
  652.  *
  653.  * Purpose:
  654.  *  Handles the WM_INITMENU message for the frame window.  Depending
  655.  *  on the existence of an active window, menu items are selectively
  656.  *  enabled and disabled.
  657.  *
  658.  * Parameters:
  659.  *  hMenu           HMENU of the menu to intialize
  660.  *  iMenu           UINT position of the menu.
  661.  *
  662.  * Return Value:
  663.  *  None
  664.  */
  665.  
  666. void CSchmooFrame::UpdateMenus(HMENU hMenu, UINT iMenu)
  667.     {
  668.     LPCDocument pDoc;
  669.     BOOL        fOK=FALSE;
  670.     BOOL        fCallDefault=TRUE;
  671.     UINT        i;
  672.     UINT        uTemp;
  673.     UINT        uTempE;
  674.     UINT        uTempD;
  675.  
  676.     pDoc=m_pCL->ActiveDocument();
  677.  
  678.     uTempE=MF_ENABLED | MF_BYCOMMAND;
  679.     uTempD=MF_DISABLED | MF_GRAYED | MF_BYCOMMAND;
  680.     uTemp=((NULL!=pDoc) ? uTempE : uTempD);
  681.  
  682.     //File menu:  If there is no current document window, disable Import.
  683.     if (m_phMenu[0]==hMenu)
  684.         EnableMenuItem(hMenu, IDM_FILEIMPORT, uTemp);
  685.  
  686.     //Color menu:  no document, no commands
  687.     if (m_phMenu[2]==hMenu)
  688.         {
  689.         EnableMenuItem(hMenu, IDM_COLORBACKGROUND, uTemp);
  690.         EnableMenuItem(hMenu, IDM_COLORLINE,       uTemp);
  691.         fCallDefault=FALSE;
  692.         }
  693.  
  694.     //Line menu:  no document, no commands
  695.     if (m_phMenu[3]==hMenu)
  696.         {
  697.         for (i=IDM_LINEMIN; i<=IDM_LINEMAX; i++)
  698.             EnableMenuItem(hMenu, i, uTemp);
  699.  
  700.         fCallDefault=FALSE;
  701.         }
  702.  
  703.     if (fCallDefault)
  704.         CFrame::UpdateMenus(hMenu, iMenu);
  705.  
  706.     return;
  707.     }
  708.  
  709.  
  710.  
  711.  
  712.  
  713.  
  714. /*
  715.  * CSchmooFrame::UpdateGizmos
  716.  *
  717.  * Purpose:
  718.  *  Enables and disables gizmos depending on whether we have
  719.  *  a document or not.
  720.  *
  721.  * Parameters:
  722.  *  None
  723.  *
  724.  * Return Value:
  725.  *  None
  726.  */
  727.  
  728. void CSchmooFrame::UpdateGizmos(void)
  729.     {
  730.     LPCDocument pDoc;
  731.     BOOL        fEnable;
  732.     UINT        i;
  733.  
  734.     //Let the default hack on its gizmos.
  735.     CFrame::UpdateGizmos();
  736.  
  737.     pDoc=m_pCL->ActiveDocument();
  738.     fEnable=(NULL!=pDoc);
  739.  
  740.     //No document, disable just about everything
  741.     m_pGB->Enable(IDM_FILEIMPORT, fEnable);
  742.  
  743.     m_pGB->Enable(IDM_COLORBACKGROUND, fEnable);
  744.     m_pGB->Enable(IDM_COLORLINE,       fEnable);
  745.  
  746.     for (i=IDM_LINEMIN; i <= IDM_LINEMAX; i++)
  747.         m_pGB->Enable(i, fEnable);
  748.  
  749.     return;
  750.     }
  751.  
  752.  
  753.  
  754.  
  755.  
  756.  
  757. /*
  758.  * CSchmooFrame::CheckLineSelection
  759.  *
  760.  * Purpose:
  761.  *  Maintains the bitmap menu and the gizmos for the line selection.  Both
  762.  *  are mutially exclusive option lists where a selection in one has to
  763.  *  affect the other.
  764.  *
  765.  * Parameters:
  766.  *  uID             UINT ID of the item to be selected
  767.  *
  768.  * Return Value:
  769.  *  None
  770.  */
  771.  
  772. void CSchmooFrame::CheckLineSelection(UINT uID)
  773.     {
  774.     UINT        i;
  775.     HMENU       hMenu;
  776.     LPCDocument pDoc;
  777.  
  778.     hMenu=GetMenu(m_hWnd);
  779.  
  780.     //Uncheck all lines initially.
  781.     for (i=IDM_LINEMIN; i<=IDM_LINEMAX; i++)
  782.         CheckMenuItem(hMenu, i, MF_UNCHECKED | MF_BYCOMMAND);
  783.  
  784.     CheckMenuItem(hMenu, uID, MF_CHECKED | MF_BYCOMMAND);
  785.     m_pGB->Check(uID, TRUE);
  786.  
  787.     pDoc=m_pCL->ActiveDocument();
  788.     m_pGB->Enable(uID, (NULL!=pDoc));
  789.  
  790.     return;
  791.     }
  792.  
  793.  
  794.  
  795.  
  796. //CHAPTER10MOD
  797. /*
  798.  * CSchmooFrame::UpdateEmbeddingUI
  799.  *
  800.  * Purpose:
  801.  *  Puts the application into the user interface for editing an
  802.  *  embedded object, manipulating menus and title bars.
  803.  *
  804.  * Parameters:
  805.  *  fEmbedding      BOOL TRUE to go into the mode, FALSE to leave it.
  806.  *  pszApp          LPCSTR name of the container application as received
  807.  *                  in IOleObject::SetHostNames.
  808.  *  pszObj          LPCSTR name of the object in the container as received
  809.  *                  in IOleObject::SetHostNames.
  810.  *
  811.  * Return Value:
  812.  *  None
  813.  */
  814.  
  815. void CSchmooFrame::UpdateEmbeddingUI(BOOL fEmbedding, LPCDocument pDoc
  816.     , LPCSTR pszApp, LPCSTR pszObj)
  817.     {
  818.     HMENU           hMenu;
  819.     char            szTemp[256];
  820.  
  821.     //First let's play with the File menu.
  822.     hMenu=m_phMenu[0];
  823.  
  824.     //Remove or add the File New, Open, and Save items
  825.     if (fEmbedding)
  826.         {
  827.         DeleteMenu(m_phMenu[0], IDM_FILENEW,   MF_BYCOMMAND);
  828.         DeleteMenu(m_phMenu[0], IDM_FILEOPEN,  MF_BYCOMMAND);
  829.         DeleteMenu(m_phMenu[0], IDM_FILECLOSE, MF_BYCOMMAND);
  830.         DeleteMenu(m_phMenu[0], IDM_FILESAVE,  MF_BYCOMMAND);
  831.  
  832.         //Save As->Save Copy As
  833.         ModifyMenu(m_phMenu[0], IDM_FILESAVEAS, MF_BYCOMMAND, IDM_FILESAVEAS
  834.             , PSZ(IDS_SAVECOPYAS));
  835.  
  836.         }
  837.     else
  838.         {
  839.         InsertMenu(m_phMenu[0], 0, MF_BYPOSITION, IDM_FILENEW,   PSZ(IDS_NEW));
  840.         InsertMenu(m_phMenu[0], 1, MF_BYPOSITION, IDM_FILEOPEN,  PSZ(IDS_OPEN));
  841.         InsertMenu(m_phMenu[0], 2, MF_BYPOSITION, IDM_FILESAVE,  PSZ(IDS_SAVE));
  842.         InsertMenu(m_phMenu[0], 3, MF_BYPOSITION, IDM_FILECLOSE, PSZ(IDS_SAVE));
  843.  
  844.         //Save Copy As->Save As
  845.         ModifyMenu(m_phMenu[0], IDM_FILESAVEAS, MF_BYCOMMAND, IDM_FILESAVEAS
  846.             , PSZ(IDS_SAVEAS));
  847.         }
  848.  
  849.     //Change "Exit" to "Exit & Return to xx" or vice-versa for SDI
  850.     if (fEmbedding)
  851.         wsprintf(szTemp, PSZ(IDS_EXITANDRETURN), (LPSTR)pszObj);
  852.     else
  853.         lstrcpy(szTemp, PSZ(IDS_EXIT));
  854.  
  855.     ModifyMenu(m_phMenu[0], IDM_FILEEXIT, MF_STRING, IDM_FILEEXIT, szTemp);
  856.     DrawMenuBar(m_hWnd);
  857.  
  858.     //Now let's pzlay with the gizmobar.
  859.     m_pGB->Show(IDM_FILENEW,   !fEmbedding);
  860.     m_pGB->Show(IDM_FILEOPEN,  !fEmbedding);
  861.     m_pGB->Show(IDM_FILECLOSE, !fEmbedding);
  862.     m_pGB->Show(IDM_FILESAVE,  !fEmbedding);
  863.  
  864.     //Enable what's left appropriately.
  865.     UpdateGizmos();
  866.  
  867.     //Now play with the title bar.
  868.  
  869.     //IDS_EMBEDDINGCAPTION is MDI/SDI sensitive in SCHMOO.RC.
  870.     wsprintf(szTemp, PSZ(IDS_EMBEDDINGCAPTION), pszObj);
  871.  
  872.     /*
  873.      * Remember that in MDI situations that Windows takes care of
  874.      * the frame window caption bar when the document is maximized.
  875.      */
  876.    #ifdef MDI
  877.     SetWindowText(pDoc->Window(), szTemp);
  878.    #else
  879.     SetWindowText(m_hWnd, szTemp);
  880.    #endif
  881.  
  882.     return;
  883.     }
  884.  
  885. //End CHAPTER10MOD
  886.